package tcm.test.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tcm.test.pojo.dto.UserDTO;
import tcm.test.pojo.entity.Order;
import tcm.test.pojo.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {

    //注册用户
    @Insert("insert into users (id, username, password, gender, date_of_birth, phone, image, update_time, create_time) " +
            "VALUES" +
            " (#{id},#{username},#{password},#{gender},#{dateOfBirth},#{phone},#{image},#{updateTime},#{createTime})")
    void register(User u);

    //根据id查询用户
    @Select("select * from users where id=#{id}")
    User getById(Long id);

    //根据id更新用户
    void update(User u);

    //根据id删除用户
    @Delete("delete from users where id=#{id}")
    void delete(Long id);

    @Select("select * from orders where user_id=#{id}")
    List<Order> getOrders(Long id);
}
